package com.reservationserver.controller.admin;

import com.reservationpojo.domin.vo.AdminPingpongvo;
import com.reservationpojo.entity.Pingpong;
import com.reservationpojo.utils.Result;
import com.reservationserver.mapper.admin.AdminPingpongMapper;
import com.reservationserver.service.admin.AdmintPingpongService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/adminpingpong")
@Tag(name = "乒乓球管理界面")
public class AdminpingpongController {
    private final AdmintPingpongService admintPingpongService;
    private final AdminPingpongMapper adminPingpongMapper;
    /**
     * 扫码入场
     * @param pingpong
     * @return 预约记录列表
     * ce
     */
    @Operation(summary = "查询任意预约")
    @GetMapping("/selectreservation")
    public Result selectreservation(@RequestBody AdminPingpongvo pingpong){
        log.info("查询预约记录:{}",pingpong);
        return Result.success(admintPingpongService.selectreservation(pingpong));
    }
    /**
     * 需要传递预约状态 创建时间
     * @param pingpong 全部的预约信息
     * @return 无
     * ce
     */
    @Operation(summary = "取消指定预约")
    @PostMapping("/deleteReservation")
    public Result deleteReservation(@RequestBody Pingpong pingpong){
        log.info("管理员取消指定预约");
        admintPingpongService.deleteReservation(pingpong);
        return Result.success("已取消该预约");
    }
    /**
     * 根据对二维码扫描结果查库
     * @param pingpong 二维码中的信息
     * @return 无
     * ce
     */
    @Operation(summary = "管理员扫码入场")
    @PostMapping("/checkReservation")
    public Result checkReservation(@RequestBody Pingpong pingpong){
        log.info("管理员扫码入场");
        if(admintPingpongService.checkReservation(pingpong)==null){
            return Result.success("无预约记录");
        }
        return Result.success("可入场");
    }
    //ce
    @Operation(summary = "关闭指定场地")
    @PostMapping("/shutDownCourt")
    public Result shutDownCourt(String courtId,LocalDateTime starttime){
        if(starttime.minusDays(2).isAfter(LocalDateTime.now())){
            return Result.success("不可关闭两天以内的场地");
        }
        log.info("关闭场地：{}",courtId);
        admintPingpongService.shutDownCourt(courtId,starttime);
        return Result.success("已关闭该场地");
    }
    //ce
    @Operation(summary = "开启指定场地")
    @PostMapping("/openCourt")
    public Result openCourt(String courtId){
        log.info("开启场地");
        admintPingpongService.openCourt(courtId);
        return Result.success("已开启场地");
    }
    //ce
    @Operation(summary = "查看被关闭场地")
    @PostMapping("/checkCourt")
    public Result checkCourt(){
        log.info("查看场地");
        return Result.success(admintPingpongService.checkCourt());
    }
    @Operation(summary = "是否允许重复预约")
    @GetMapping("/uprepeate")
    public Result uprepeate(){
        log.info("修改是否允许重复预约");
        adminPingpongMapper.uprepeate();
        return Result.success();
    }
}
